﻿#include"FITKAcousticsPhysicsMgrAdaptor.h"
#include "FITKAcousticsHDF5Writer.h"
#include "FITKAcousticsHDF5Reader.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKAcousticsAbsPhysicsProp.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKPhyscisPropertyBeam.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKPhyscisPropertyUniform.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKPhyscisPropertyGeneralLaminate.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKPhyscisPropertyGeneralLaminateIsoLayer.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKPhyscisPropertyRibbed.h"
#include "FITK_Component/FITKAcousticsPhysics/FITKPhyscisPropertyRibInfo.h"



#include "FITK_Interface/FITKInterfaceIO/FITKHDF5FileTool.h"
#include <H5Cpp.h>


bool IO::FITKAcousticsPhysicsMgrAdaptor::adaptR()
{
    Acoustics::FITKAcousticsPhysicsPropManager* physicsPropMgr =
        dynamic_cast<Acoustics::FITKAcousticsPhysicsPropManager*>(_dataObj);
    if (physicsPropMgr == nullptr || _reader == nullptr) return false;
    m_toolp = _reader->getHDF5FileTool();//初始化工具
    if (m_toolp == nullptr)
    {
        return false;
    }

    std::tuple<bool, H5::Group>Ret = m_toolp->openGp("PhysicaProperties");
    if (std::get<0>(Ret) == false) { return false; }
    H5::Group PhysicaPropertiesGroup = std::get<1>(Ret);

    bool BeamRet = this->readBeams(PhysicaPropertiesGroup, physicsPropMgr);
    bool UniformPlatsRet = this->readUniformPlats(PhysicaPropertiesGroup, physicsPropMgr);
    bool GeneralLaminateRet = this->readGeneralLaminate(PhysicaPropertiesGroup, physicsPropMgr);
    bool RibbedphysicalRet = this->readRibbedphysical(PhysicaPropertiesGroup, physicsPropMgr);

    return BeamRet && UniformPlatsRet&&GeneralLaminateRet&&RibbedphysicalRet;
}

bool IO::FITKAcousticsPhysicsMgrAdaptor::adaptW()
{
    Acoustics::FITKAcousticsPhysicsPropManager* physicsPropMgr =
        dynamic_cast<Acoustics::FITKAcousticsPhysicsPropManager*>(_dataObj);
    if (physicsPropMgr == nullptr || _writer == nullptr) return false;
    m_toolp = _writer->getHDF5FileTool();//初始化工具

    //获取梁数据
    QList<Acoustics::FITKAcousticsAbsPhysicsProp*>APPBeams = physicsPropMgr->getPhysicsProps(Acoustics::FITKAcousticsAbsPhysicsProp::AcousticsPhyscisPropType::APPBeam);

    //获取均质板数据
    QList<Acoustics::FITKAcousticsAbsPhysicsProp*>APPUniformPlats = physicsPropMgr->getPhysicsProps(Acoustics::FITKAcousticsAbsPhysicsProp::AcousticsPhyscisPropType::APPUniformPlat);
    //获取自由阻尼层合板数据
    QList<Acoustics::FITKAcousticsAbsPhysicsProp*>APPGeneralLaminatePhysicalPropertys = physicsPropMgr->getPhysicsProps(Acoustics::FITKAcousticsAbsPhysicsProp::AcousticsPhyscisPropType::APPGeneralLaminatePhysicalProperty);
    //获取加强筋数据
    QList<Acoustics::FITKAcousticsAbsPhysicsProp*>APPRibbedphysicalPropertys = physicsPropMgr->getPhysicsProps(Acoustics::FITKAcousticsAbsPhysicsProp::AcousticsPhyscisPropType::APPRibbedphysicalProperty);


    std::tuple<bool, H5::Group> Ret = m_toolp->createGp("PhysicaProperties");     //创建物理性质组
    if (std::get<0>(Ret) == false) { return false; }
    H5::Group PhysicaPropertiesGroup = std::get<1>(Ret);

    bool BeamRet = this->writeBeams(PhysicaPropertiesGroup, APPBeams);                            //写梁数据
    bool UniformPlatsRet = this->writeUniformPlats(PhysicaPropertiesGroup, APPUniformPlats);      //写均质板数据
    bool GeneralLaminateRet = this->writeGeneralLaminate(PhysicaPropertiesGroup, APPGeneralLaminatePhysicalPropertys);//写自由阻尼层合板数据
    bool RibbedphysicalRet = this->writeRibbedphysical(PhysicaPropertiesGroup, APPRibbedphysicalPropertys);//写加强筋数据

    return BeamRet && UniformPlatsRet && GeneralLaminateRet &&RibbedphysicalRet;
}

bool IO::FITKAcousticsPhysicsMgrAdaptor::writeBeams(H5::Group & PhysicsPropGroup, QList<Acoustics::FITKAcousticsAbsPhysicsProp*> Beams)
{
    //创建的HDF5目录结构
    const char *Path = "PhysicaProperties/Beams";

    int count = Beams.size();;//获取数据行数


    //在组下创建组，并为组附加数据个数属性
    m_toolp->CreateGroupAndAttr(PhysicsPropGroup, "Beams", "BeamssCount", count);

    //获取刚刚创建的组
    H5::Group thisGroup = m_toolp->GetPathGroup(Path);

    for (int i = 0; i < count; ++i)
    {
        Acoustics::FITKPhyscisPropertyBeam* ObjP = dynamic_cast<Acoustics::FITKPhyscisPropertyBeam*>(Beams.at(i));
        if (ObjP == nullptr)
        {
            continue;
        }
        QString Name = ObjP->getDataObjectName();       //获取名称
        int MaterialID = ObjP->getMaterialID();         //获取所使用的材料ID
        double SecondMomentX = ObjP->getSecondMomentX();//获取Ixx(截面惯性矩x)
        double SecondMomentY = ObjP->getSecondMomentY();//获取Iyy(截面惯性矩y)
        double PolarMoment = ObjP->getPolarMoment();    //获取Jzz(截面极惯性矩)
        double TorsionalConstant = ObjP->getTorsionalConstant();//获取Qzz(扭转常数)
        double CrossSectionArea = ObjP->getCrossSectionArea();  //截面积
        double Perimeter = ObjP->getPerimeter();      //截面积周长
        double ShearOffsetX = ObjP->getShearOffsetX();//剪心偏移X
        double ShearOffsetY = ObjP->getShearOffsetY();//剪心偏移Y
        QString Describe = ObjP->getDescribe();       //获取描述
        float Color[3] = { 0.0,0.0,0.0 };
        ObjP->getColor(Color);                        //表格颜色数据
        int ID = ObjP->getDataObjectID();             //获取数据ID

        //检查字符串输入是否有特殊字符
        m_toolp->CheckString(Name);
        m_toolp->CheckString(Describe);


        //在组下创建具体材料属性,并绑定到组
        m_toolp->CreateNameFromAttr(thisGroup, i, Name.toStdString());

        std::tuple<bool, H5::Group>Ret = m_toolp->createGp(thisGroup, Name);//创建子节点
        if (std::get<0>(Ret) == false) { continue; }

        H5::Group subGroup = std::get<1>(Ret);

        std::vector<bool>writeResultBools;//存储此次写入时返回成功与否数据
        //将数据写入到具体属性中
        writeResultBools.push_back(m_toolp->writeGroupAttrStr(subGroup, "Name", Name.toStdString()));
        writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "MaterialID", MaterialID));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "SecondMomentX", SecondMomentX));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "SecondMomentY", SecondMomentY));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "PolarMoment", PolarMoment));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "TorsionalConstant", TorsionalConstant));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "CrossSectionArea", CrossSectionArea));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "Perimeter", Perimeter));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "ShearOffsetX", ShearOffsetX));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "ShearOffsetY", ShearOffsetY));
        writeResultBools.push_back(m_toolp->writeGroupAttrStr(subGroup, "Describe", Describe.toStdString()));
        writeResultBools.push_back(m_toolp->CreateOneDArrayDataSetFloat(subGroup, 3, "Color", Color));
        writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "ID", ID));
        bool allBool = this->areAllTrue(writeResultBools);
        if (allBool == false)
        {
            //如果不是全部都为true则，写入失败，写该数据终止
            return false;
        }
    }
    return true;
}

bool IO::FITKAcousticsPhysicsMgrAdaptor::readBeams(H5::Group & PhysicsPropGroup, Acoustics::FITKAcousticsPhysicsPropManager * mager)
{
    if (mager==nullptr)
    {
        return false;
    }
    std::tuple<bool, H5::Group>Ret = m_toolp->openGp(PhysicsPropGroup, "Beams");//打开组
    if (std::get<0>(Ret) == false) { return false; }
    H5::Group thisMaterialsGroup = std::get<1>(Ret);

    std::tuple<bool, H5::Attribute>RetAttr = m_toolp->openAttribut(thisMaterialsGroup, "BeamssCount"); //打开组个数属性
    if (std::get<0>(RetAttr) == false) { return false; }
    H5::Attribute CountAttrattr = std::get<1>(RetAttr);

    int count = -1;
    CountAttrattr.read(H5::PredType::NATIVE_INT, &count);
    for (int i = 0; i < count; ++i)
    {
        //通过转换i为str，获取该str属性下对应组的名称(具体材料名称)
        std::string subGroupName = m_toolp->readGroupAttrName(thisMaterialsGroup, i);
        //打开子组
        std::tuple<bool, H5::Group>RetGroup = m_toolp->openGp(thisMaterialsGroup, subGroupName.data());
        if (std::get<0>(RetGroup) == false) { continue; }//打不开则退出此次
        H5::Group subGroup = std::get<1>(RetGroup);


        std::string Name{};
        int MaterialID = -1;
        double SecondMomentX = 0.0;
        double SecondMomentY = 0.0;
        double PolarMoment = 0.0;
        double TorsionalConstant = 0.0;
        double CrossSectionArea = 0.0;
        double Perimeter = 0.0;
        double ShearOffsetX = 0.0;
        double ShearOffsetY = 0.0;
        std::string Describe{};
        std::vector<float>Color{};
        int ID = -1;             //获取数据ID,注意和上面MaterialID的差别


        Name = subGroupName;
        m_toolp->readGroupint(subGroup, "MaterialID", &MaterialID);
        m_toolp->readGroupDouble(subGroup, "SecondMomentX", &SecondMomentX);
        m_toolp->readGroupDouble(subGroup, "SecondMomentY", &SecondMomentY);
        m_toolp->readGroupDouble(subGroup, "PolarMoment", &PolarMoment);
        m_toolp->readGroupDouble(subGroup, "TorsionalConstant", &TorsionalConstant);
        m_toolp->readGroupDouble(subGroup, "CrossSectionArea", &CrossSectionArea);
        m_toolp->readGroupDouble(subGroup, "Perimeter", &Perimeter);
        m_toolp->readGroupDouble(subGroup, "ShearOffsetX", &ShearOffsetX);
        m_toolp->readGroupDouble(subGroup, "ShearOffsetY", &ShearOffsetY);
        m_toolp->readGroupStr(subGroup, "Describe", Describe);
        m_toolp->ReadOneDArrayDataSetFloat(subGroup, "Color", Color);//读取DataSet中颜色
        m_toolp->readGroupint(subGroup, "ID", &ID);

        //构建泡沐材料类，并填充数据
        Acoustics::FITKPhyscisPropertyBeam*newObjData = new Acoustics::FITKPhyscisPropertyBeam();
        if (newObjData==nullptr)
        {
            continue;
        }

        newObjData->setDataObjectName(RestoreStr(Name));
        newObjData->setMaterialID(MaterialID);
        newObjData->setSecondMomentX(SecondMomentX);
        newObjData->setSecondMomentY(SecondMomentY);
        newObjData->setPolarMoment(PolarMoment);
        newObjData->setTorsionalConstant(TorsionalConstant);
        newObjData->setCrossSectionArea(CrossSectionArea);
        newObjData->setPerimeter(Perimeter);
        newObjData->setShearOffsetX(ShearOffsetX);
        newObjData->setShearOffsetY(ShearOffsetY);
        newObjData->setDescribe(RestoreStr(Describe));
        if (Color.size() == 3)
        {
            newObjData->setColor(Color.at(0), Color.at(1), Color.at(2));
        }

        Core::FITKAbstractDataIDAlter a;
        a.modifyDataID(newObjData, ID);
        mager->appendDataObj(newObjData);
    }
    return true;
}

bool IO::FITKAcousticsPhysicsMgrAdaptor::writeUniformPlats(H5::Group & PhysicsPropGroup, QList<Acoustics::FITKAcousticsAbsPhysicsProp*> UniformPlats)
{
    //创建的HDF5目录结构
    const char *Path = "PhysicaProperties/UniformPlats";

    int count = UniformPlats.size();;//获取数据行数


    //在组下创建组，并为组附加数据个数属性
    m_toolp->CreateGroupAndAttr(PhysicsPropGroup, "UniformPlats", "UniformPlatsCount", count);

    //获取刚刚创建的组
    H5::Group thisGroup = m_toolp->GetPathGroup(Path);

    for (int i = 0; i < count; ++i)
    {
        Acoustics::FITKPhyscisPropertyUniform* ObjP = dynamic_cast<Acoustics::FITKPhyscisPropertyUniform*>(UniformPlats.at(i));
        if (ObjP == nullptr)
        {
            continue;
        }
        QString Name = ObjP->getDataObjectName();       //获取名称
        int MaterialID = ObjP->getMaterialID();         //获取所使用的材料ID
        double Thickness = ObjP->getThickness();        //获取厚度
        QString Describe = ObjP->getDescribe();         //获取描述
        float Color[3] = { 0.0,0.0,0.0 };
        ObjP->getColor(Color);                          //表格颜色数据
        int ID = ObjP->getDataObjectID();               //获取数据ID
        //检查字符串输入是否有特殊字符
        m_toolp->CheckString(Name);
        m_toolp->CheckString(Describe);

        //在组下创建具体材料属性,并绑定到组
        m_toolp->CreateNameFromAttr(thisGroup, i, Name.toStdString());

        std::tuple<bool, H5::Group>Ret = m_toolp->createGp(thisGroup, Name);//创建子节点
        if (std::get<0>(Ret) == false) { continue; }

        H5::Group subGroup = std::get<1>(Ret);
        std::vector<bool>writeResultBools;
        writeResultBools.push_back(m_toolp->writeGroupAttrStr(subGroup, "Name", Name.toStdString()));
        writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "MaterialID", MaterialID));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "Thickness", Thickness));
        writeResultBools.push_back(m_toolp->writeGroupAttrStr(subGroup, "Describe", Describe.toStdString()));
        writeResultBools.push_back(m_toolp->CreateOneDArrayDataSetFloat(subGroup, 3, "Color", Color));
        writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "ID", ID));
        bool allBool = this->areAllTrue(writeResultBools);
        if (allBool == false)
        {
            //如果不是全部都为true则，写入失败，写该数据终止
            return false;
        }
    }
    return true;
}

bool IO::FITKAcousticsPhysicsMgrAdaptor::readUniformPlats(H5::Group & PhysicsPropGroup, Acoustics::FITKAcousticsPhysicsPropManager * mager)
{
    if (mager==nullptr)
    {
        return false;
    }
    std::tuple<bool, H5::Group>Ret = m_toolp->openGp(PhysicsPropGroup, "UniformPlats");//打开组
    if (std::get<0>(Ret) == false) { return false; }
    H5::Group thisMaterialsGroup = std::get<1>(Ret);

    std::tuple<bool, H5::Attribute>RetAttr = m_toolp->openAttribut(thisMaterialsGroup, "UniformPlatsCount"); //打开组个数属性
    if (std::get<0>(RetAttr) == false) { return false; }
    H5::Attribute CountAttrattr = std::get<1>(RetAttr);

    int count = -1;
    CountAttrattr.read(H5::PredType::NATIVE_INT, &count);
    for (int i = 0; i < count; ++i)
    {
        //通过转换i为str，获取该str属性下对应组的名称(具体材料名称)
        std::string subGroupName = m_toolp->readGroupAttrName(thisMaterialsGroup, i);
        //打开子组
        std::tuple<bool, H5::Group>RetGroup = m_toolp->openGp(thisMaterialsGroup, subGroupName.data());
        if (std::get<0>(RetGroup) == false) { continue; }//打不开则退出此次
        H5::Group subGroup = std::get<1>(RetGroup);


        std::string Name{};
        int MaterialID = -1;
        double Thickness = 0.0;
        std::string Describe{};
        std::vector<float>Color{};
        int ID = -1;             //获取数据ID,注意和上面MaterialID的差别


        Name = subGroupName;
        m_toolp->readGroupint(subGroup, "MaterialID", &MaterialID);
        m_toolp->readGroupDouble(subGroup, "Thickness", &Thickness);
        m_toolp->readGroupStr(subGroup, "Describe", Describe);
        m_toolp->ReadOneDArrayDataSetFloat(subGroup, "Color", Color);//读取DataSet中颜色
        m_toolp->readGroupint(subGroup, "ID", &ID);

        //构建泡沐材料类，并填充数据
        Acoustics::FITKPhyscisPropertyUniform*newObjData = new Acoustics::FITKPhyscisPropertyUniform();
        if (newObjData==nullptr)
        {
            continue;
        }

        newObjData->setDataObjectName(RestoreStr(Name));
        newObjData->setMaterialID(MaterialID);
        newObjData->setThickness(Thickness);
        newObjData->setDescribe(RestoreStr(Describe));
        if (Color.size() == 3)
        {
            newObjData->setColor(Color.at(0), Color.at(1), Color.at(2));
        }

        Core::FITKAbstractDataIDAlter a;
        a.modifyDataID(newObjData, ID);
        mager->appendDataObj(newObjData);
    }
    return true;
}

bool IO::FITKAcousticsPhysicsMgrAdaptor::writeGeneralLaminate(H5::Group & PhysicsPropGroup, QList<Acoustics::FITKAcousticsAbsPhysicsProp*> GeneralLaminates)
{
    //创建的HDF5目录结构
    const char *Path = "PhysicaProperties/GeneralLaminates";

    int count = GeneralLaminates.size();//获取数据行数


    //在组下创建组，并为组附加数据个数属性
    m_toolp->CreateGroupAndAttr(PhysicsPropGroup, "GeneralLaminates", "GeneralLaminatesCount", count);

    //获取刚刚创建的组
    H5::Group thisGroup = m_toolp->GetPathGroup(Path);

    for (int i = 0; i < count; ++i)
    {
        Acoustics::FITKPhyscisPropertyGeneralLaminate* ObjP = dynamic_cast<Acoustics::FITKPhyscisPropertyGeneralLaminate*>(GeneralLaminates.at(i));
        if (ObjP == nullptr)
        {
            continue;
        }
        QString Name = ObjP->getDataObjectName();       //获取名称

        std::vector<int>LayerMaterialID;
        std::vector<double>LayerThickness;
        std::vector<double>LayerAngle;
        std::vector<int>LayerDLFSplectrumID;


        int LayerCount = ObjP->getLayerCount();//获取层数
        //获取一组中使用的其他的
        for (int i = 0; i < LayerCount; ++i)
        {
            Acoustics::FITKPhyscisPropertyGeneralLaminateIsoLayer* LayerDate = ObjP->getDataByIndex(i);//获取每一层
            if (LayerDate == nullptr)
            {
                continue;
            }
            LayerMaterialID.push_back(LayerDate->getMaterialID());         //获取普通层压板每一层使用的材料ID
            LayerThickness.push_back(LayerDate->getThickness());           //获取厚度
            LayerAngle.push_back(LayerDate->getAngle());                   //获取角度
            LayerDLFSplectrumID.push_back(LayerDate->getDLFSplectrumID()); //获取损耗因子id
        }

        int MaterialID = ObjP->getMaterialID();       //获取普通层压板材料ID
        QString Describe = ObjP->getDescribe();       //获取描述
        float Color[3] = { 0.0,0.0,0.0 };
        ObjP->getColor(Color);                        //表格颜色数据
        int ID = ObjP->getDataObjectID();             //获取数据ID


       //检查字符串输入是否有特殊字符
        m_toolp->CheckString(Name);
        m_toolp->CheckString(Describe);

        //在组下创建具体材料属性,并绑定到组
        m_toolp->CreateNameFromAttr(thisGroup, i, Name.toStdString());

        std::tuple<bool, H5::Group>Ret = m_toolp->createGp(thisGroup, Name);//创建子节点
        if (std::get<0>(Ret) == false) { continue; }

        H5::Group subGroup = std::get<1>(Ret);
        std::vector<bool>writeResultBools;
        writeResultBools.push_back(m_toolp->writeGroupAttrStr(subGroup, "Name", Name.toStdString()));
        writeResultBools.push_back(m_toolp->CreateOneDarrayDataSetInt(subGroup, "LayerMaterialID", LayerMaterialID));
        writeResultBools.push_back(m_toolp->CreateOneDarrayDataSetDouble(subGroup, "LayerThickness", LayerThickness));
        writeResultBools.push_back(m_toolp->CreateOneDarrayDataSetDouble(subGroup, "LayerAngle", LayerAngle));
        writeResultBools.push_back(m_toolp->CreateOneDarrayDataSetInt(subGroup, "LayerDLFSplectrumID", LayerDLFSplectrumID));
        writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "LayerCount", LayerCount));
        writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "MaterialID", MaterialID));
        writeResultBools.push_back(m_toolp->writeGroupAttrStr(subGroup, "Describe", Describe.toStdString()));
        writeResultBools.push_back(m_toolp->CreateOneDArrayDataSetFloat(subGroup, 3, "Color", Color));
        writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "ID", ID));
        bool allBool = this->areAllTrue(writeResultBools);
        if (allBool == false)
        {
            //如果不是全部都为true则，写入失败，写该数据终止
            return false;
        }
    }
    return true;
}

bool IO::FITKAcousticsPhysicsMgrAdaptor::readGeneralLaminate(H5::Group & PhysicsPropGroup, Acoustics::FITKAcousticsPhysicsPropManager * mager)
{
    if (mager==nullptr)
    {
        return false;
    }
    std::tuple<bool, H5::Group>Ret = m_toolp->openGp(PhysicsPropGroup, "GeneralLaminates");//打开组
    if (std::get<0>(Ret) == false) { return false; }
    H5::Group thisMaterialsGroup = std::get<1>(Ret);

    std::tuple<bool, H5::Attribute>RetAttr = m_toolp->openAttribut(thisMaterialsGroup, "GeneralLaminatesCount"); //打开组个数属性
    if (std::get<0>(RetAttr) == false) { return false; }
    H5::Attribute CountAttrattr = std::get<1>(RetAttr);

    int count = -1;
    CountAttrattr.read(H5::PredType::NATIVE_INT, &count);
    for (int i = 0; i < count; ++i)
    {
        //通过转换i为str，获取该str属性下对应组的名称(具体材料名称)
        std::string subGroupName = m_toolp->readGroupAttrName(thisMaterialsGroup, i);
        //打开子组
        std::tuple<bool, H5::Group>RetGroup = m_toolp->openGp(thisMaterialsGroup, subGroupName.data());
        if (std::get<0>(RetGroup) == false) { continue; }//打不开则退出此次
        H5::Group subGroup = std::get<1>(RetGroup);


        std::string Name{};
        int MaterialID = -1;//普通层压板材料ID为-1
        std::vector<int>LayerMaterialID{};
        std::vector<double>LayerThickness{};
        std::vector<double>LayerAngle{};
        std::vector<int>LayerDLFSplectrumID{};
        int LayerCount = 0;//获取层数
        std::string Describe{};
        std::vector<float>Color{};
        int ID = -1;

        Name = subGroupName;
        m_toolp->readGroupint(subGroup, "MaterialID", &MaterialID);//存储的时候就是-1
        m_toolp->readGroupint(subGroup, "LayerCount", &LayerCount);
        m_toolp->ReadOneDArrayDataSetInt(subGroup, "LayerMaterialID", LayerMaterialID);
        m_toolp->ReadOneDArrayDataSetDouble(subGroup, "LayerThickness", LayerThickness);
        m_toolp->ReadOneDArrayDataSetDouble(subGroup, "LayerAngle", LayerAngle);
        m_toolp->ReadOneDArrayDataSetInt(subGroup, "LayerDLFSplectrumID", LayerDLFSplectrumID);
        m_toolp->readGroupStr(subGroup, "Describe", Describe);
        m_toolp->ReadOneDArrayDataSetFloat(subGroup, "Color", Color);//读取DataSet中颜色
        m_toolp->readGroupint(subGroup, "ID", &ID);

        Acoustics::FITKPhyscisPropertyGeneralLaminate*newObjData = new Acoustics::FITKPhyscisPropertyGeneralLaminate();
        if (newObjData==nullptr)
        {
            continue;
        }
        newObjData->setDataObjectName(RestoreStr(Name));
        newObjData->setMaterialID(MaterialID);

        if (LayerMaterialID.size() != LayerThickness.size() ||
            LayerThickness.size() != LayerAngle.size() ||
            LayerAngle.size() != LayerDLFSplectrumID.size())
        {
            continue;//这4个数组必定一致大小，否则不能读取
        }
        if (LayerCount != LayerMaterialID.size())
        {
            continue;//数组大小应与层数一致否则不能读取
        }
        for (int j = 0; j < LayerCount; ++j)
        {
            //创建使用的每一层数据
            Acoustics::FITKPhyscisPropertyGeneralLaminateIsoLayer* newLayer = new Acoustics::FITKPhyscisPropertyGeneralLaminateIsoLayer;//创建每一层
            if (newLayer==nullptr)
            {
                continue;
            }
            newLayer->setMaterialID(LayerMaterialID.at(j));
            newLayer->setThickness(LayerThickness.at(j));
            newLayer->setAngle(LayerAngle.at(j));
            newLayer->setDLFSplectrumID(LayerDLFSplectrumID.at(j));
            newObjData->insertDataObj(j, newLayer);
        }
        newObjData->setDescribe(RestoreStr(Describe));
        if (Color.size() == 3)
        {
            newObjData->setColor(Color.at(0), Color.at(1), Color.at(2));
        }

        Core::FITKAbstractDataIDAlter a;
        a.modifyDataID(newObjData, ID);
        mager->appendDataObj(newObjData);
    }
    return true;
}


bool IO::FITKAcousticsPhysicsMgrAdaptor::writeRibbedphysical(H5::Group & PhysicsPropGroup, QList<Acoustics::FITKAcousticsAbsPhysicsProp*> Ribbedphysicals)
{
    //创建的HDF5目录结构
    const char *Path = "PhysicaProperties/Ribbedphysicals";

    int count = Ribbedphysicals.size();//获取数据行数

    //在组下创建组，并为组附加数据个数属性
    m_toolp->CreateGroupAndAttr(PhysicsPropGroup, "Ribbedphysicals", "RibbedphysicalsCount", count);

    //获取刚刚创建的组
    H5::Group thisGroup = m_toolp->GetPathGroup(Path);


    for (int i = 0; i < count; ++i)
    {
        Acoustics::FITKPhyscisPropertyRibbed* ObjP = dynamic_cast<Acoustics::FITKPhyscisPropertyRibbed*>(Ribbedphysicals.at(i));
        if (ObjP == nullptr)
        {
            continue;
        }
        QString Name = ObjP->getDataObjectName(); //获取名称
        QString Describe = ObjP->getDescribe();   //获取描述
        float Color[3] = { 0.0,0.0,0.0 };
        ObjP->getColor(Color);                   //表格颜色数据
        int ID = ObjP->getDataObjectID();        //获取数据ID

        int SkinPropID = ObjP->getSkinPropID();  //获取SkinID
        double  BaseAngle = ObjP->getBaseAngle();//获取角度

        //Core::FITKAbstractDataObject*dobj= FITKDATAREPO->getDataByID(SkinPropID);

        Acoustics::FITKPhyscisPropertyRibInfo* r1 = ObjP->getDri1RibInfo();//获取第一条筋数据
        if (r1==nullptr)
        {
            continue;
        }
        double r1Orientation = r1->getOrientation();                       //获取第一条梁截面方向角度
        int r1BeamPropID = r1->getBeamPropID();                            //获取该筋使用的梁ID
        double r1Spacing = r1->getSpacing();      //获取间距
        double r1SpacingDevFraction = r1->getSpacingDevFraction();         //加筋间距的标准偏差比例
        double r1Offset = r1->getOffset();        //获取中心偏移


        //Core::FITKAbstractDataObject*dobj2 = FITKDATAREPO->getDataByID(r1BeamPropID);


        //检查字符串输入是否有特殊字符
        m_toolp->CheckString(Name);
        m_toolp->CheckString(Describe);

        //在组下创建具体材料属性,并绑定到组
        m_toolp->CreateNameFromAttr(thisGroup, i, Name.toStdString());

        std::tuple<bool, H5::Group>Ret = m_toolp->createGp(thisGroup, Name);//创建子节点
        if (std::get<0>(Ret) == false) { continue; }
        H5::Group subGroup = std::get<1>(Ret);
        std::vector<bool>writeResultBools;

        if (ObjP->isDir2Enabled())
        {
            //判断是否有第二条筋
            Acoustics::FITKPhyscisPropertyRibInfo* r2 = ObjP->getDri2RibInfo();//获取第二条筋数据
            if (r2==nullptr)
            {
                continue;
            }
            double r2Orientation = r2->getOrientation();                       //获取第二条梁截面方向角度
            int r2BeamPropID = r2->getBeamPropID();                            //获取第二梁使用的梁ID
            double r2Spacing = r2->getSpacing();      //获取间距
            double r2SpacingDevFraction = r2->getSpacingDevFraction();         //加筋间距的标准偏差比例
            double r2Offset = r2->getOffset();        //获取中心偏移

            writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "r2Orientation", r2Orientation));
            writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "r2BeamPropID", r2BeamPropID));
            writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "r2Spacing", r2Spacing));
            writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "r2SpacingDevFraction", r2SpacingDevFraction));
            writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "r2Offset", r2Offset));

        }

        writeResultBools.push_back(m_toolp->writeGroupAttrStr(subGroup, "Name", Name.toStdString()));
        writeResultBools.push_back(m_toolp->writeGroupAttrStr(subGroup, "Describe", Describe.toStdString()));
        writeResultBools.push_back(m_toolp->CreateOneDArrayDataSetFloat(subGroup, 3, "Color", Color));
        writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "ID", ID));
        writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "SkinPropID", SkinPropID));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "BaseAngle", BaseAngle));

        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "r1Orientation", r1Orientation));
        writeResultBools.push_back(m_toolp->writeGroupAttrInt(subGroup, "r1BeamPropID", r1BeamPropID));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "r1Spacing", r1Spacing));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "r1SpacingDevFraction", r1SpacingDevFraction));
        writeResultBools.push_back(m_toolp->writeGroupAttrDouble(subGroup, "r1Offset", r1Offset));

        bool allBool = this->areAllTrue(writeResultBools);
        if (allBool == false)
        {
            //如果不是全部都为true则，写入失败，写该数据终止
            return false;
        }
    }
    return true;
}




bool IO::FITKAcousticsPhysicsMgrAdaptor::readRibbedphysical(H5::Group & PhysicsPropGroup, Acoustics::FITKAcousticsPhysicsPropManager * mager)
{
    if (mager==nullptr)
    {
        return false;
    }
    std::tuple<bool, H5::Group>Ret = m_toolp->openGp(PhysicsPropGroup, "Ribbedphysicals");//打开组
    if (std::get<0>(Ret) == false) { return false; }
    H5::Group thisMaterialsGroup = std::get<1>(Ret);

    std::tuple<bool, H5::Attribute>RetAttr = m_toolp->openAttribut(thisMaterialsGroup, "RibbedphysicalsCount"); //打开组个数属性
    if (std::get<0>(RetAttr) == false) { return false; }
    H5::Attribute CountAttrattr = std::get<1>(RetAttr);

    int count = -1;
    CountAttrattr.read(H5::PredType::NATIVE_INT, &count);
    for (int i = 0; i < count; ++i)
    {
        //通过转换i为str，获取该str属性下对应组的名称(具体材料名称)
        std::string subGroupName = m_toolp->readGroupAttrName(thisMaterialsGroup, i);
        //打开子组
        std::tuple<bool, H5::Group>RetGroup = m_toolp->openGp(thisMaterialsGroup, subGroupName.data());
        if (std::get<0>(RetGroup) == false) { continue; }//打不开则退出此次
        H5::Group subGroup = std::get<1>(RetGroup);


        std::string Name{};
        std::string Describe{};
        std::vector<float>Color{};
        int ID = -1;            //本数据的ID
        int SkinPropID = -1;    //本数据中用到的Skin的ID
        double  BaseAngle = 0.0;//角度


        Name = subGroupName;
        m_toolp->readGroupStr(subGroup, "Describe", Describe);
        m_toolp->ReadOneDArrayDataSetFloat(subGroup, "Color", Color);//读取DataSet中颜色
        m_toolp->readGroupint(subGroup, "ID", &ID);
        m_toolp->readGroupint(subGroup, "SkinPropID", &SkinPropID);
        m_toolp->readGroupDouble(subGroup, "BaseAngle", &BaseAngle);


        Acoustics::FITKPhyscisPropertyRibbed*newObjData = new Acoustics::FITKPhyscisPropertyRibbed();
        if (newObjData==nullptr)
        {
            continue;
        }
        newObjData->setDataObjectName(RestoreStr(Name));
        newObjData->setDescribe(RestoreStr(Describe));
        if (Color.size() == 3)
        {
            newObjData->setColor(Color.at(0), Color.at(1), Color.at(2));
        }

        newObjData->setSkinPropID(SkinPropID);
        newObjData->setBaseAngle(BaseAngle);
        Core::FITKAbstractDataIDAlter a;
        a.modifyDataID(newObjData, ID);
        mager->appendDataObj(newObjData);


        //第一条筋
        double r1Orientation = 0.0;
        int r1BeamPropID = -1;
        double r1Spacing = 0.0;
        double r1SpacingDevFraction = 0.0;
        double r1Offset = 0.0;

        m_toolp->readGroupDouble(subGroup, "r1Orientation", &r1Orientation);
        m_toolp->readGroupint(subGroup, "r1BeamPropID", &r1BeamPropID);
        m_toolp->readGroupDouble(subGroup, "r1Spacing", &r1Spacing);
        m_toolp->readGroupDouble(subGroup, "r1SpacingDevFraction", &r1SpacingDevFraction);
        m_toolp->readGroupDouble(subGroup, "r1Offset", &r1Offset);

        Acoustics::FITKPhyscisPropertyRibInfo* r1 = newObjData->getDri1RibInfo();
        if (r1==nullptr)
        {
            continue;
        }
        r1->setOrientation(r1Orientation);
        r1->setBeamPropID(r1BeamPropID);
        r1->setSpacing(r1Spacing);
        r1->setSpacingDevFraction(r1SpacingDevFraction);
        r1->setOffset(r1Offset);

        if (m_toolp->CheckGoupHaveAttribute(subGroup, "r2Orientation"))//判断是否有第二条
        {
            double r2Orientation = 0.0;
            int r2BeamPropID = -1;
            double r2Spacing = 0.0;
            double r2SpacingDevFraction = 0.0;
            double r2Offset = 0.0;

            m_toolp->readGroupDouble(subGroup, "r2Orientation", &r2Orientation);
            m_toolp->readGroupint(subGroup, "r2BeamPropID", &r2BeamPropID);
            m_toolp->readGroupDouble(subGroup, "r2Spacing", &r2Spacing);
            m_toolp->readGroupDouble(subGroup, "r2SpacingDevFraction", &r2SpacingDevFraction);
            m_toolp->readGroupDouble(subGroup, "r2Offset", &r2Offset);

            Acoustics::FITKPhyscisPropertyRibInfo* r2 = newObjData->getDri2RibInfo();
            if (r2==nullptr)
            {
                continue;
            }

            r2->setOrientation(r2Orientation);
            r2->setBeamPropID(r2BeamPropID);
            r2->setSpacing(r2Spacing);
            r2->setSpacingDevFraction(r2SpacingDevFraction);
            r2->setOffset(r2Offset);
        }
    }
    return true;
}

bool IO::FITKAcousticsPhysicsMgrAdaptor::areAllTrue(const std::vector<bool>& Data)
{
    return std::all_of(Data.begin(), Data.end(), [](bool b) { return b; });
}

QString IO::FITKAcousticsPhysicsMgrAdaptor::RestoreStr(std::string data)
{
    QString CheckStr = QString::fromStdString(data);
    m_toolp->RestoreString(CheckStr);//检查是否原来有字符/，有则转换
    return CheckStr;
}